package engine.core
{
	import flash.utils.*;
	
	public class RxContext
	{
		private static const MAX_LENGTH:int = 256;
		private static var s_strings:Vector.<String> = new Vector.<String>;
		private static var s_pops:Vector.<int> = new Vector.<int>;
		private static var s_globals:Dictionary = new Dictionary();
		
		public function RxContext()
		{
		}
		
		public static function Push(_arg1:String, ... _args) : void
		{
			var _local3:String;
			if (s_strings.length == MAX_LENGTH)
			{
				RxLog.Warning("Context stack overflow");
			}
			else
			{
				s_pops.push(s_strings.length);
				_local3 = _arg1 + " (";
				_local3 = _local3 + _args.join(", ");
				_local3 = _local3 + ")";
				s_strings.push(_local3);
			}
		}
		
		public static function Trace(... args) : void
		{
			if (s_strings.length == MAX_LENGTH)
			{
				RxLog.Warning("Context stack overflow");
			}
			else
			{
				s_strings.push(args.join(", "));
			}

		}
		
		public static function Pop() : void
		{
			if (s_strings.length == 0)
			{
				RxLog.Warning("Context stack underflow");
			}
			else
			{
				s_strings.length = s_pops.pop();
			}

		}
		
		public static function SetGlobal(param1:String, param2:String) : void
		{
			s_globals[param1] = param2;

		}
		
		public static function GetStack() : String
		{
			var _loc_3:int = 0;
			var _loc_4:String = null;
			var _loc_1:* = new Vector.<String>;
			var _loc_2:int = 0;
			for each (_loc_3 in s_pops)
			{
				
				while (_loc_2 < _loc_3)
				{
					
					_loc_1.push("\ttrace: " + s_strings[_loc_2]);
					_loc_2++;
				}
				_loc_1.push("\tat: " + s_strings[_loc_2]);
				_loc_2++;
			}
			while (_loc_2 < s_strings.length)
			{
				
				_loc_1.push("\ttrace: " + s_strings[_loc_2]);
				_loc_2++;
			}
			for (_loc_4 in s_globals)
			{
				
				_loc_1.push("\tglobal: " + _loc_4 + "=" + s_globals[_loc_4]);
			}
			return _loc_1.join("\n");
		}
	}
}